package com.pro.springbootshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pro.springbootshop.entity.Collect;
import com.pro.springbootshop.entity.Wares;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface CollectMapper extends BaseMapper<Collect> {
    @Select("select * from collect where buyer_id=#{buyerId} limit #{pageNo},#{limit}")
    @Results(
            {
                    @Result(column = "order_id",property = "orderId"),
                    @Result(column = "wares_id",property = "waresId"),
                    @Result(column = "buyer_id",property = "buyerId"),
                    @Result(column = "wares_id",property = "wares",javaType = Wares.class,
                            one=@One(select = "com.pro.springbootshop.mapper.WaresMapper.selectById")
                    )
            }
    )
    List<Collect> getCollectList(String buyerId, Integer pageNo, Integer limit);
    @Select("select * from collect where buyer_id=#{buyerId}")
    List<Collect> getCollectListCount(String buyerId);
    @Select("select * from collect where buyer_id=#{buyerId} and wares_id=#{waresId}")
    Collect getCollect(String buyerId,Integer waresId);
}
